using System;
using Microsoft.Win32;
using Sedge.Core.Utils;

namespace Sedge.Core.Configuration.Property
{
	public class RegPropertyHandler : IPropertyHandler
	{
		private readonly string _key;
		private readonly string _value;

		public RegPropertyHandler(ReportableObject owner, string key, string value)
		{
			_key = PropertyResolver.ResolveValue(owner, key);
			_value = PropertyResolver.ResolveValue(owner, value);
		}

		public string GetValue()
		{
			string value = String.Empty;
			try
			{
				value = (string)Registry.GetValue(_key, _value, String.Empty);
			}
			catch (Exception e)
			{
				ErrorHandler.Warning(e.Message);
			}
			return value;
		}
	}
}